package com.drcoffee.drcoffeemall.service.impl;

import com.drcoffee.drcoffeemall.entry.Document;
import com.drcoffee.drcoffeemall.mapper.DocumentMapper;
import com.drcoffee.drcoffeemall.service.DocumentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class DocumentServiceImpl implements DocumentService {
    @Autowired
    DocumentMapper documentMapper;

    @Override
    public Map<String, Object> getDocument(Integer machine_id, String search) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            List<Document> documentList;
            documentList = documentMapper.getDocument(machine_id, '%' + search + '%');
            resultMap.put("documentList", documentList);
        } catch (Exception e) {
            log.error("===================== getDocument()异常： =====================", e);
            resultMap.put("reason", e.getMessage());
        }
        return resultMap;
    }

    @Override
    public Map<String, Object> getDocumentAll() {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            List<Document> documentList = documentMapper.getDocumentAll();
            resultMap.put("documentList", documentList);
        } catch (Exception e) {
            log.error("===================== getDocumentAll()异常： =====================", e);
            resultMap.put("reason", e.getMessage());
        }
        return resultMap;
    }
}
